/**
 * 
 */
package com.test;

import static org.junit.Assert.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
import org.junit.validator.PublicClassValidator;

import com.dao.OrderDao;
import com.dao.ProductmDao;
import com.entity.Order;
import com.entity.Product;
import com.sqlSessionFactory.SqlSessionFactoryUtil;

/**
 * @author Administrator
 *
 */
public class Ordertest {

	@Test
	public void test() {
		//test1();
		
		//test2();
		//test3();
	//test4();
		//test5();
	}
	
	public void test5() {
		SqlSession sqlSession=SqlSessionFactoryUtil.getSqlSession();	
		String oid = "1727e284c6534c619e5a7fe293a5747e";
		OrderDao orderDao = sqlSession.getMapper(OrderDao.class);
		Map<String,Object > map=new HashMap();//创建一个map集合
		map.put("reciverAddress", "小哈佛");
		map.put("oid","305d15ede6904eefbcf6af5853780872");
		orderDao.updateOrder(map);
		System.out.println("更新的地址是");
		sqlSession.commit();//事物提交
		sqlSession.close();
		
		
	}
	
	public void test4() {
	SqlSession sqlSession=SqlSessionFactoryUtil.getSqlSession();	
	String oid = "1727e284c6534c619e5a7fe293a5747e";
	OrderDao orderDao = sqlSession.getMapper(OrderDao.class);
	//注册dao层接口
	int  order=orderDao.deleteOrder(oid);
	System.out.println("删除的记录数");
	sqlSession.commit();//事物提交
	sqlSession.close();
	

	}
	
	
	
	public void test3() {
		String oid = "1727e284c6534c619e5a7fe293a5747e";
		SqlSession sqlSession = SqlSessionFactoryUtil.getSqlSession();
		OrderDao orderDao = sqlSession.getMapper(OrderDao.class);
		Order order = orderDao.queryOrder(oid);
		System.out.println(order.toString());
		sqlSession.close();
	}
	public void test2() {
		
		SqlSession sqlSession = SqlSessionFactoryUtil.getSqlSession();
		OrderDao orderDao = sqlSession.getMapper(OrderDao.class);
		List<Order> recorder = orderDao.queryAllOrder();
		for(Order order : recorder) {
			System.out.println(order.toString());
		}
		
		sqlSession.close();
	}
	
	
	
	
	
	public void test1() {
		Order order = new Order();
		String oid = UUID.randomUUID().toString().replace("-", "");
		String user_id = "0003";
		//String reciverName = "可乐";
		String reciverAddress = "小可爱的家";
		String reciverPhone = "15028875565";
		int payState = 0;
		double money = 140;
		order.setOid(oid);
		order.setUser_id(user_id);
		order.setReciverName("李四");
		order.setReciverAddress(reciverAddress);
		order.setReciverPhone(reciverPhone);
		order.setPayState(payState);
		order.setMoney(money);
		SqlSession sqlSession = SqlSessionFactoryUtil.getSqlSession();
		OrderDao orderDao = sqlSession.getMapper(OrderDao.class);//注册dao层接口
		int recorder = orderDao.addOrder(order);
		System.out.println(oid);
		System.out.println(recorder);
		sqlSession.commit();//事物提交
		sqlSession.close();
		
	}
	
}
